import {
  Queue,
  DeQueue,
} from './index';

export function hotPotato(elementList: (number | string)[], num: number) {
  const queue = new Queue(...elementList);
  const eliminated: any[] = [];
  
  while (queue.size() > 1) {
    for (let i = 0; i < num; i++) {
      queue.enqueue(queue.dequeue());
    }

    eliminated.push(queue.dequeue());
  }

  return {
    eliminated,
    winner: queue.peak(),
  };
}

/**
 * @description palidrome checker Ignore punctuation and case
 * @param str string to be checked
 */
export function palidromeChecker(str: string) {
  const lowerStr = str.replace(/[\W_]/g, '').toLowerCase().split('');
  const dequeue = new DeQueue(...lowerStr);
  
  let isEqual = true;
  while (dequeue.size() > 1 && isEqual === true) {
    const firstChar = dequeue.removeFront();
    const lastChar = dequeue.removeBack();

    isEqual = firstChar === lastChar;
  }
  
  return isEqual;
}
